package Day4;

import java.util.Scanner;

public class Day04_01 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        int pre = 1, cur = 1, next = 2;
        int ret = 0;
        while(true) {
            if(n <= cur && n >= pre) {
                System.out.println(Math.min( n - pre, cur - n));
                break;
            }

            pre = cur;
            cur = next;
            next = pre + cur;
        }
    }
}
//https://www.nowcoder.com/practice/18ecd0ecf5ef4fe9ba3f17f8d00d2d66?tpId=122&tqId=33668&ru=/exam/oj